<template>
	<view>
		<view class="login-top"></view>
		<view class="login-main">
			<view class="main-main">
				<view class="login-main-title">
					<text class="text">{{mainmsg.au_name}}  {{mainmsg.au_tel}}</text>
					<text class="text" style="float: right;" @click="AddMyStoreInfo">{{StoreInfotitle}}</text>
				</view>
				<view v-if="!StoreInfo">
				<view class="main-top">
					<view class="mian-list">
						<view class="img" @tap="enterIn">
							<image src="../../static/img/home.png"></image>
							<view>
								<text class="top-text">{{mainmsg.au_nickname}}</text>
								<text class="text">{{mainmsg.au_birth}}|{{mainmsg.au_addr}}</text><!-- {{mainmsg.au_addr}} -->
							</view>
						</view>
					</view>
				</view>
				<!-- <view v-if="storeFixInfo.length>1">
					<view class="login-main-title">
						<text class="text">我的维修单</text>
					</view>
					<view v-for="(item,index) in storeFixInfo" :key="item.Id">
						<view class="main-top" style="margin-top: 5rpx;" @tap='chooseFix(item.Id)'>
							<view class="mian-list">
								<view class="img">
									<view>
										<text class="top-text">{{ item.ro_title }}</text>
										<text class="text" v-if="!item.enble">{{item.ro_person}} | {{item.ro_addr}} | 已关闭</text>
										<text class="text" v-else>{{item.ro_person}} | {{item.ro_addr}}</text>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view> -->
				<!-- <view class="main-top">
					<view class="mian-list">
						<view class="img" @tap="enterfix">
							<image src="../../static/logo.png"></image>
							<view>
								<text class="top-text">电费维修单</text>
								<text class="text">2021-4-9 | 维修单</text>
							</view>
						</view>
					</view>
				</view>
				<view class="main-top" style="margin-top: 5px;">
					<view class="mian-list">
						<view class="img" @tap="enterfix">
							<image src="../../static/logo.png"></image>
							<view>
								<text class="top-text">水费维修单</text>
								<text class="text">2021-4-9 | 维修单</text>
							</view>
						</view>
					</view> -->
				<!-- </view> -->
				<view class="login-main-title">
					<text class="text">新增缴费</text>
					<!-- <text class="location">位置</text> -->
				</view>
				<view class="main-class">
					<view class="mian-list" v-for="(item, index) in PayVariety" :key="index" @tap="enterIn(item)">
						<view class="img">
							<image src="../../static/img/power.png"></image>
						</view>
						<view class="text">{{item.title}}</view>
					</view>
				</view>
				<view class="login-main-title">
					<text class="text">当前店：XXX店</text>
					<!-- <text class="location">位置</text> -->
				</view>
				</view>
				<view v-else>
					<view class="main-top" style="margin-top: 5rpx;" v-for="(item, index) in storeInfo" :key="item.Id" @tap='choose(item.Id)'>
						<view class="mian-list">
							<view class="img">
								<image :src="item.st_img_photo1"></image>
								<view>
									<text class="top-text">{{ item.st_storename }}</text>
									<text class="text">{{item.st_man}} | {{item.st_khyh}}</text>
								</view>
							</view>
						</view>
					</view>
					<view class="main-top" style="margin-top: 10rpx;display: flex; justify-content:center" @tap="nagator('AddMyStoreInfo')">
							<image src="../../static/img/add.jpg" mode="" style="height: 9vh;width: 9vh;margin-top: 1vh;"></image>
					</view>
				</view>
				<view class="main-bottom">
					<text>
						缴费记录
					</text>
					<text @click="nagator('AddRepairOrder')">
						维修申请
					</text>
					<text>
						绑定商户
					</text>
				</view>
			</view>
		</view>
		<view class="">
				<u-popup mode="right" v-model="show" >
					<view class="upp-bg">
					<view style="width: 50vw;height: 10vh;text-align: center;line-height: 4vh;">
						<view>
							{{mainmsg.au_name}}
						</view>
						<view class="">
							{{mainmsg.au_tel}}
						</view>
					</view>
					<view class="popup prop-list" @click="nagator('ModifyAppUserInfo')">
						<!-- <navigator url="./ModifyAppUserInfo"> -->
							修改用户信息
						<!-- </navigator> -->
					</view>
					<view class=" prop-list" @click="nagator('ModifyAppUserLogonPwd')">
						<!-- <navigator url="./ModifyAppUserLogonPwd"> -->
							修改用户密码
						<!-- </navigator> -->
					</view>
					<view class=" prop-list" @click="nagator('AddMyStoreInfo')">
						<!-- <navigator url="./AddMyStoreInfo"> -->
							申请店铺信息
						<!-- </navigator> -->
					</view>
					<view class=" prop-list" @click="nagator('GetMyStoreInfos')">
						<!-- <navigator url="./GetMyStoreInfos"> -->
							查询商户信息
						<!-- </navigator> -->
					</view>
					<view class=" prop-list" @click="nagator('GetMyHomes')">
						<!-- <navigator url="./GetMyHomes"> -->
							查看住户信息
						<!-- </navigator> -->
					</view>
					<view class=" prop-list" @click="nagator('AddMyHome')">
						<!-- <navigator url="./AddMyHome"> -->
							新增住户信息
						<!-- </navigator> -->
					</view>
					<view class=" prop-list" @click="nagator('GetRepairOrders')">
						<!-- <navigator url="./GetRepairOrders"> -->
							维修单信息
						<!-- </navigator> -->
					</view>
					<view class=" prop-list" @click="nagator('AddRepairOrder')">
						<!-- <navigator url="./GetRepairOrders"> -->
							新增维修单
						<!-- </navigator> -->
					</view>
					</view>
				</u-popup>
			</view>
	</view>
</template>

<script>
	import http from '../common/http.js'; 
	export default {
		data() {
			return {
				pageIndex:1,  //商户模式下分页
				StoreInfotitle:'切换商户模式',
				StoreInfo:false, //商户模式不显示
				storeInfo:{},
				storeFixInfo:{},
				PayVariety:{},
				
				show:false,
				token:'',
				mainmsg:{}
			}
		},
		onShow() {

		},
		onLoad() {
			// this.begin()
			this.token = uni.getStorageSync('token');
			this.mainmsg = uni.getStorageSync('mainmsg');
			if(this.mainmsg.au_birth){
				let str = this.mainmsg.au_birth.substring(this.mainmsg.au_birth.indexOf("(") + 1,this.mainmsg.au_birth.indexOf(")"))
				this.mainmsg.au_birth = this.formatDate(str)
			}
			
			let _this = this
			uni.request({
				url: _this.$title + 'PayMent/GetPayVariety',
				header: {
					'auth': _this.token
				},
				success: (res) => {
					if (res.statusCode === 200) {
						_this.PayVariety = res.data
					} else {
						uni.showToast({
							icon: "none",
							title: res.data.message
						})
					}
				}
			});
		},
		
		//触底加载，触底时加载下一页
		onReachBottom:function(){
			
			// if(this.StoreInfo){
			// 	this.pageIndex = this.pageIndex + 1
			// 	this.rechBottom()
			// }
		},
		methods: {
			formatDate(str) {
				str = Number(str)
				var date = new Date(str); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
				var Y = date.getFullYear() + '-';
				var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
				var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
				var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
				var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
				var s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
				return Y + M + D
			
			},
			
			onNavigationBarButtonTap(e) {
				this.show = true
			},
			
			nagator(msg){
				this.show = false
				uni.navigateTo({
					url: msg
				});
			},
			
			choose(e){
				uni.navigateTo({
					url: 'AddMyStoreInfo?id=' + e
				});
			},
			
			chooseFix(e){
				uni.navigateTo({
					url: 'AddRepairOrder?id=' + e
				});
			},
			
			AddMyStoreInfo(){
				if(this.StoreInfotitle === '切换住户模式'){
					this.StoreInfotitle = '切换商户模式'
					this.StoreInfo = false
					return
				}
				
				this.StoreInfotitle = '切换住户模式'
				this.StoreInfo = true
				//分页接口有问题，返回的都是全部数据
				let data = {
					"AppUserInfoId": this.mainmsg.Id,
					"onePageSize": 50,
					'pageIndex': 1
				}
				
				let _this = this
				uni.request({
					url: _this.$title + 'AppUserFeatures/GetMyStoreInfos',
					data: data,
					header: {
						'auth': _this.token
					},
					success: (res) => {
						if (res.data.status === 200) {
							_this.storeInfo = res.data.data
						} else {
							uni.showToast({
								icon: "none",
								title: res.data.message
							})
						}
					}
				});
			},
			enterStoreInfo(){
				uni.navigateTo({
					url: 'AddMyStoreInfo'
				});
			},
			enterIn(s) {
				if(!s.title){
					s.title = '电'
				}
				if(!s.num){
					s.num = 2
				}
				
				uni.setStorage({
					key: 'ele',
					data: s,
					success: function() {
						
					}
				});
				uni.navigateTo({
					url: 'cost?title=' + s.title + '&Id=' + s.num
				});
			},
			
			// enterfix() {
			// 	uni.navigateTo({
			// 		url: 'fix'
			// 	});
			// }
		}
	}
</script>

<style lang="scss">
	
	.upp-bg{
		height: 100%;
		background: linear-gradient(to right, #00aaff 0%,#aaffff 100%);
	}
	.prop-list{
		height: 2rem;
		line-height: 2rem;
		width: 30vw;
		margin-top: 3vh;
		margin-left: 5vw;
		border-bottom: 1px solid black;
	}
	// .popup{
	// 	margin-top: 10vh;
	// }
	
	.login-top {
		background-color: #18ab4e;
		height: 20vh;
	}

	.login-main {
		background-color: #F1F1F1;
		height: 100vh;
		border-top-right-radius: 4vw;
		border-top-left-radius: 4vw;
		margin-top: -1vh;
	}

	.main-main {
		margin-left: 5vw;
		margin-right: 5vw;
	}

	.login-main-title {
		height: 10vh;

		.text {
			line-height: 10vh;
			font-weight: 600;
		}

		.location {
			line-height: 10vh;
			font-weight: 600;
			float: right;
		}

	}
	
	

	.main-top {
		background-color: white;
		height: 9vh;
		width: 100%;
		padding: 0 0 40upx 0;
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;
		align-items: center;
		border-radius: 3vw;
		box-shadow: 0px 0px 10px #d6d6d6;

		.mian-list {
			display: flex;
			flex-wrap: wrap;
			text-align: center;
			.img {
				width: 100%;
				display: flex;
				justify-content: center;
				flex-direction: row;

				image {
					top: 25%;
					margin-left: 5vw;
					width: 3rem;
					height: 3rem;
				}

				text {
					margin-left: 3vw;
					display: flex;
					flex-direction: row;
					width: 15rem;
				}

				.top-text {
					padding-top: 1vh;
					font-size: large;
					font-weight: 200;
				}

				.text {
					color: #8F8F94;
					font-size: medium;
				}
			}
			

		}
	}

	.main-class {
		// background-color: white;
		width: 100%;
		padding: 0 0 0 0;
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;
		align-items: center;

		.mian-list {
			background-color: white;
			box-sizing: border-box;
			height: 30vw;
			width: 30vw;
			display: flex;
			flex-wrap: wrap;
			text-align: center;
			align-items: center;
			border: 1px solid #F1F1F1;
			box-shadow: 0px 0px 3px #888888;

			.img {
				width: 100%;
				display: flex;
				justify-content: center;

				image {
					width: 3rem;
					height: 3rem;
				}

			}

			.text {
				// margin-top: 1rem;
				width: 100%;
				display: flex;
				justify-content: center;
				// font-size: 24upx;
				color: #3c3c3c;
			}
		}
	}

	.main-bottom {
		margin-top: 5vh;
		height: 10vh;
		display: flex;
		justify-content: space-around;

		text {
			justify-content: center;
		}

	}
</style>
